//
//  CollectionViewController.m
//  OCMicroBlog
//
//  Created by 002 on 15/11/6.
//  Copyright © 2015年 002. All rights reserved.
//

#import "NewFeatureViewController.h"
#import "NewFeatureCell.h"

@interface NewFeatureViewController ()

@property(nonatomic,strong) UIImageView *iconView;

@end

@implementation NewFeatureViewController

// 可重用标识
static NSString * const reuseIdentifier = @"NewFeatureViewControllerCellID";

// 新特性图片数量
NSInteger WBNewFeatureCount = 4;

- (void)viewDidLoad {
    [super viewDidLoad];

    // 注册cell
    [self.collectionView registerClass:[NewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    self.collectionView.bounces = false;
    self.collectionView.showsHorizontalScrollIndicator = false;
    self.collectionView.pagingEnabled = true;
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return WBNewFeatureCount;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    // Configure the cell
//    cell.backgroundColor = HFRandomColor;
    
    cell.imageIndex = indexPath.item + 1;
    
    return cell;
}

// 当 scrollView 停止滚的时候
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    // 计算当前滚动页数
    NSInteger page = (int)(scrollView.contentOffset.x / scrollView.bounds.size.width);
    
    // 判断是否最后一张图片
    if (page != WBNewFeatureCount - 1) {
        return;
    }
    
    // 取cell , 播放动画
    NewFeatureCell *cell = (NewFeatureCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:page inSection:0]];
    [cell showStartButtonAnim];
}

@end
